/*
 * ColorRangeHSV.h
 *
 *  Created on: Dec 27, 2009
 *      Author: vuk
 */

#ifndef COLORRANGEHSV_H_
#define COLORRANGEHSV_H_

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <iostream>
#include <fstream>
#include "ColorHSV.h"

class ColorRangeHSV
{
protected:

	ColorHSV low, hi;

public:

	ColorRangeHSV(const char *file);

	ColorRangeHSV(const ColorRangeHSV &c)
	{
		low=c.low;
		hi=c.hi;
	}

	ColorRangeHSV(const ColorHSV &l, const ColorHSV &h)
	{
		low=l;
		hi=h;
	}

	ColorRangeHSV(const uchar &lowH=0, const uchar &lowS=0, const uchar &lowV=0,
					const uchar &hiH=0, const uchar &hiS=0, const uchar &hiV=0)
	:low(lowH, lowS, lowV), hi(hiH, hiS, hiV) {	}


	ColorRangeHSV(const int &lowH, const int &lowS, const int &lowV,
						const int &hiH, const int &hiS, const int &hiV)
	:low(lowH, lowS, lowV), hi(hiH, hiS, hiV) {	}

	ColorRangeHSV& operator=(const ColorRangeHSV &c)
	{
		if(&c!=this)
		{
			low=c.low;
			hi=c.hi;
		}
		return *this;
	}

	bool operator==(const ColorHSV &c) const //proverava da li je zadata boja u opsegu
	{
		if(low.loreH(hi))
			return low<=c && hi>=c;
		else
			return ( (c.horeH(low) && c.loreH(179) ) || (c.horeH(0) && c.loreH(hi) ) ) && c.horeSV(low) && c.loreSV(hi);
	}

	bool operator==(const uchar *c) const//proverava da li je zadati pokazivac koji pokazuje na hsv iz nekog frejma u opsegu OPASNO!!! Ali efikasno
	{
		if(low.loreH(hi))
			return low<=c && hi>=c;
		else
			return ( (c[0]>=low.H() && c[0]<=(180) ) || (c[0]>=0 && c[0]<=(hi.H()) ) ) && c[1]>=low.S() && c[1]<=hi.S() && c[2]>=low.V() && c[2]<=hi.V();
	}

	bool operator!=(const ColorHSV &c) const //proverava da li je zadata boja nije u opsegu
	{
		return !(*this==c);
	}

	bool operator!=(const uchar *c) const //proverava da li je zadata boja nije u opsegu
	{
		return !(*this==c);
	}

	friend ostream &operator<<(ostream &out, const ColorRangeHSV& c)
	{
		return out<<"Hi:  "<<c.hi<<"      Low: "<<c.low<<endl;
	}

};

#endif /* COLORRANGEHSV_H_ */
